﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonLibrary.Web.Core
{
    /// <summary>
    /// Default repository class for the entities
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class EntityRepository<T> where T : class
    {
        /// <summary>
        /// Creates an item in the repository.
        /// </summary>
        /// <param name="item"></param>
        public virtual void Create(T item)
        {
        }


        /// <summary>
        /// Gets an item from the repository by it's id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual T Get(int id)
        {
            return default(T);
        }


        /// <summary>
        /// Deletes an item from the repository
        /// </summary>
        /// <param name="item"></param>
        public virtual void Delete(T item)
        {
        }


        /// <summary>
        /// Deletes an item from the repository
        /// </summary>
        /// <param name="item"></param>
        public virtual void Delete(int id)
        {
        }


        /// <summary>
        /// Updates the item from the repository
        /// </summary>
        /// <param name="item"></param>
        public virtual void Update(T item)
        {
        }


        /// <summary>
        /// Gets all the items from the repository.
        /// </summary>
        /// <returns></returns>
        public virtual List<T> GetAll()
        {
            return null;
        }


        /// <summary>
        /// Commits the repository to underlying storage.
        /// </summary>
        public virtual void Commit()
        {
        }


        /// <summary>
        /// gets the id via reflection
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public int GetId(object item)
        {
            return EntityHelper.GetId(item);
        }
    }
}
